/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mathma.core.form;

import mathma.core.expr.Expression;

import mathma.core.value.Value;
import mathma.core.value.ValueType;

import java.util.ArrayList;
import java.util.List;

/**
 * @since 0.2.5
 * @author Ethan Levine
 */
public final class TypeConversionExpression<E extends Value, O extends Value>
        extends FormulaicExpression<E, O> {

    private final Expression<O> operand;

    public TypeConversionExpression(ValueType castType,
            Expression<O> expr) {
        super(castType);
        this.operand = expr;
    }

    public E evaluate() {
        // cast.
        return (E) operand.evaluate();
    }

    public Expression<O> getOperand() {
            return operand;
    }

    public List<Expression<O>> getOperands() {
        List<Expression<O>> operands = new ArrayList<Expression<O>>();
        operands.add(operand);
        return operands;
    }

    public TypeConversionExpression newInstance(List<Expression<O>> operands) {
        return new TypeConversionExpression(getType(), operands.get(0));
    }
}
